


// export function() {}

var Platform = require('Platform');
import React from 'react-native';
var {
    PixelRatio
} = React;

//如果width/SCALE > 3
var viewPort = require('Dimensions').get('window');
var width = viewPort.width;//宽度


var _scale = (Platform.OS ==='ios')?width/320: width/375;
//根据屏幕宽度调整数据
var _as = function(i) {
    if (i == 0 || i == undefined) {return 0};
    var size;
    size = i * _scale;
    if(size < 1) size = 1;
    return Math.ceil(size);

}
var _asFont = function(i) {
    if (Platform.OS ==='android' && width > 390 && viewPort.scale < 3) {
        return Math.ceil(i * (width/390));
    }
    return i;
}

/*xhdpi: 2.0
 hdpi: 1.5
 mdpi: 1.0 (baseline)
 ldpi: 0.75*/
var fontHeightRatio = 0.5 * PixelRatio.getFontScale();
//用于计算字体对应的高度值, lineHeight在安卓下无效,


var _asFontHeight = function (fontSize, lineOfNumber, lineHeight) {
    if (!lineOfNumber || lineOfNumber == 0) {
        lineOfNumber == 1;
    }

    if (Platform.OS ==='ios') {
        var x;
        if (lineHeight) {
            x = (lineHeight/fontSize);

        } else {
            x=1.2
        }
        return fontSize * lineOfNumber * x;
    } else {
        var x;
        if (lineHeight) {
            x = (lineHeight/fontSize);

        } else {
            x = 1.3
        }
        var t = PixelRatio.getFontScale()>2? lineHeight % fontSize/2 :0;
        return fontSize * (lineOfNumber) * x + t*lineOfNumber;
    }
}

 export default {
    as: _as,
    asFont: _asFont,
    asFontHeight: _asFontHeight
}
